<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户姓名" prop="realname">
        <el-input
          v-model="queryParams.realname"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="authInfoList" >
      <el-table-column label="用户ID" align="center" prop="uid" width="200"/>
      <el-table-column label="用户姓名" align="center" prop="realname" />
      <el-table-column label="身份证" align="center" prop="idcard" />
      <el-table-column label="实名认证状态" align="center" prop="authStatus" />
      <el-table-column label="实名认证记录id" align="center" prop="authRecordId" />
      <el-table-column label="头像图片" align="center" prop="headImg" />
      <el-table-column label="人脸面" align="center" prop="faceImg" />
      <el-table-column label="国徽面" align="center" prop="nationImg" />
      <el-table-column label="人脸认证分数" align="center" prop="faceSource" />
      <el-table-column label="人脸认证状态" align="center" prop="faceStatus" />
      <el-table-column label="人脸认证记录id" align="center" prop="faceRecordId" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listAuthInfo, getAuthInfo, delAuthInfo, addAuthInfo, updateAuthInfo } from "@/api/member/authInfo";

export default {
  name: "AuthInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户认证信息表格数据
      authInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        realname: null,
        idcard: null,
        authStatus: null,
        authRecordId: null,
        headImg: null,
        faceImg: null,
        nationImg: null,
        faceSource: null,
        faceStatus: null,
        faceRecordId: null,
        tenantId: null,
        deleted: null,
        creator: null,
        updater: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户认证信息列表 */
    getList() {
      this.loading = true;
      listAuthInfo(this.queryParams).then(response => {
        this.authInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        uid: null,
        realname: null,
        idcard: null,
        authStatus: null,
        authRecordId: null,
        headImg: null,
        faceImg: null,
        nationImg: null,
        faceSource: null,
        faceStatus: null,
        faceRecordId: null,
        tenantId: null,
        deleted: null,
        creator: null,
        updater: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.uid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户认证信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const uid = row.uid || this.ids
      getAuthInfo(uid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户认证信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.uid != null) {
            updateAuthInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAuthInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const uids = row.uid || this.ids;
      this.$modal.confirm('是否确认删除用户认证信息编号为"' + uids + '"的数据项？').then(function() {
        return delAuthInfo(uids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('member/authInfo/export', {
        ...this.queryParams
      }, `authInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
